package mirrormonkey.commons.transform;

import java.io.IOException;

import mirrormonkey.core.annotations.EntityHierarchy;
import mirrormonkey.framework.entity.EntityData;
import mirrormonkey.framework.entity.SyncEntity;
import mirrormonkey.state.annotations.ReceiveStateFrom;
import mirrormonkey.state.annotations.TrackValue;
import mirrormonkey.state.annotations.UpdateState;
import mirrormonkey.util.annotations.hfilter.ClassFilter;

import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.Control;

@EntityHierarchy
public class TransformUpdateControl implements SyncEntity, Control {

	public EntityData data;

	public final Spatial spatial;

	public TransformUpdateControl(Spatial forSpatial) {
		this.spatial = forSpatial;
		forSpatial.addControl(this);
	}

	@TrackValue(true)
	@UpdateState(freq = 0.05f)
	@ReceiveStateFrom(@ClassFilter(classes = ServerTransformUpdateControl.class))
	public Vector3f getLocalScale() {
		return spatial.getLocalScale();
	}

	public void setLocalScale(Vector3f scale) {
		spatial.setLocalScale(scale);
	}

	@TrackValue(true)
	@UpdateState(freq = 0.05f)
	@ReceiveStateFrom(@ClassFilter(classes = ServerTransformUpdateControl.class))
	public Vector3f getLocalTranslation() {
		return spatial.getLocalTranslation();
	}

	public void setLocalTranslation(Vector3f translation) {
		spatial.setLocalTranslation(translation);
	}

	@TrackValue(true)
	@UpdateState(freq = 0.05f)
	@ReceiveStateFrom(@ClassFilter(classes = ServerTransformUpdateControl.class))
	public Quaternion getLocalRotation() {
		return spatial.getLocalRotation();
	}

	public void setLocalRotation(Quaternion rotation) {
		spatial.setLocalRotation(rotation);
	}

	@Override
	public Control cloneForSpatial(Spatial spatial) {
		return new TransformUpdateControl(spatial);
	}

	@Override
	public void setSpatial(Spatial spatial) {
	}

	@Override
	public void setEnabled(boolean enabled) {
	}

	@Override
	public boolean isEnabled() {
		return true;
	}

	@Override
	public void update(float tpf) {
	}

	@Override
	public void render(RenderManager rm, ViewPort vp) {
	}

	@Override
	public void setData(EntityData data) {
		this.data = data;
	}

	@Override
	public EntityData getData() {
		return data;
	}

	@Override
	public void write(JmeExporter ex) throws IOException {
	}

	@Override
	public void read(JmeImporter im) throws IOException {
	}

}
